import Vue from 'vue'
import Router from 'vue-router'
import CouponList from '@/components/CouponList'
import ShopList from '@/components/ShopList'
import Home from '@/components/Home'
import Login from '@/components/Login'
Vue.use(Router)



var vuerouter= new Router({
  routes: [
    {
      path: '/',
      name: 'Home',
      component: Home
    },{
      path: '/Home',
      name: 'Home',
      component: Home,
      children:[
        {
          path: '/CouponList',
          name: 'CouponList',
          component: CouponList
        },{
          path: '/ShopList',
          name: 'ShopList',
          component: ShopList
        }
      ]
    },{
      path: '/Login',
      name: 'Login',
      component: Login
    }
  ]
})

vuerouter.beforeEach(function(to, from, next){
  var username=Vue.prototype.$cookieStore.getCookie("username");
  console.log(username);
  if(username){
    if(to.name=="Login"){
      next("/Home")
    }else{
      next();
    }
  }else{
    if(to.name=="Login"){
      next();
    }else{
      next("/Login")
    }
  }
  //to.name 路由名称：login
  //to.path 路由路径：/login
})

export default vuerouter;
